#include "imitatescene.h"

ImitateScene::ImitateScene(QWidget *parent) : QMainWindow(parent)
{
    //设置窗口
    //固定尺寸
    this->setFixedSize(mainSceneWidth,mainSceneHeight);
    //标题
    this->setWindowTitle(mainSceneName);
    //图标
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));

    //创建菜单
    QMenuBar * bar = menuBar();
    this->setMenuBar(bar);
    QMenu* startMenu = bar->addMenu("开始");
    QAction * quitAction = startMenu->addAction("退出");

    connect(quitAction,&QAction::triggered,[=](){
        this->close();
    });

    //返回按钮
    PushButton_01 * back =new PushButton_01(":/res/BackButton.png",":/res/BackButtonSelected.png");
    back->setParent(this);
    back->move(this->width() - back->width(),this->height() - back->height());

    connect(back,&PushButton_01::clicked,[=](){

        QTimer::singleShot(500,this,[=](){
            emit this->ImitatecSceneBack();
        });

    });

    PushButton_01 * menuBtn = new PushButton_01(":/res/ksyx.png");
    menuBtn->setParent(this);
    //menuBtn->setFixedSize(menuBtn->width()*10,menuBtn->height()*10);
    menuBtn->move(250,450);

    connect(menuBtn,&PushButton_01::clicked,[=](){
        this->iplay = new ImitatePlay;
        this->iplay->show();
        this->hide();

        //监听pplay的返回信号
        connect(this->iplay,&ImitatePlay::ImitateSceneBack,[=](){
            this->show();
            this->iplay->hide();

            delete this->iplay;
            this->iplay=NULL;
        });
    });


}
//绘图事件
void ImitateScene::paintEvent(QPaintEvent *){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/bfda0be809541c57e1407952d1e6042.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //标题
    pix.load(":/res/Title.png");
    painter.drawPixmap((this->width()-pix.width())*0.5,30,pix);
}
